package com.yanqu.road.server.cmd.activity.commonsupport;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonUnionSupportProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.commonsupport.CommonSupportActivity;
import com.yanqu.road.server.manager.activity.commonsupport.CommonSupportMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_COMMON_UNION_SUPPORT, desc = "支持商会")
public class CrossDoUnionSupportCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonUnionSupportProto.DoUnionSupportReq req = CommonUnionSupportProto.DoUnionSupportReq.parseFrom(packet.getBytes());
        CommonSupportActivity activity = CommonSupportMgr.getActivity(req.getActivityId(), 0);
        if(activity != null){
            CommonUnionSupportProto.DoUnionSupportResp.Builder builder = activity.support(serverId, packet.getPlayerId(), req.getUnionUid());
            if(builder.getRet() != 0){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                        YanQuMessageUtils.buildMessage(Protocol.U_COMMON_UNION_SUPPORT, builder));
            }else {
                MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                        YanQuMessageUtils.buildMessage(Protocol.S_COMMON_UNION_SUPPORT_FROM_CROSS, builder));
            }
        }else {
            MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                    YanQuMessageUtils.buildMessage(Protocol.U_COMMON_UNION_SUPPORT, CommonUnionSupportProto.DoUnionSupportResp.newBuilder().setRet(GameErrorCode.E_ACTIVITY_NO_FOUND)));
        }
    }

    @Override
    public void sendData() {

    }
}
